using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
using Metro.Admin.BusinessEntities;
using Microsoft.Practices.EnterpriseLibrary.Data;


namespace Metro.Admin.DataAccess
{
    public partial class Transaction
    {
        public Stats GetStats(DateTime date)
        {
            Stats stats = null;
            try
            {
                string sqlCommand = "SELECT min, max, [open], [close], average FROM Stats WHERE date >= @date";
                DbCommand dbCommand = metroDb.GetSqlStringCommand(sqlCommand);
                metroDb.AddInParameter(dbCommand, "@date", DbType.DateTime, date);

                using (IDataReader dataReader = metroDb.ExecuteReader(dbCommand))
                {
                    while (dataReader.Read())
                    {
                        stats = new Stats();

                        stats.Minimal = Convert.ToDecimal(dataReader["min"].ToString());
                        stats.Maximum = Convert.ToDecimal(dataReader["max"].ToString());
                        stats.Open = Convert.ToDecimal(dataReader["open"].ToString());
                        stats.Close = Convert.ToDecimal(dataReader["close"].ToString());
                        stats.Average = Convert.ToDecimal(dataReader["average"].ToString());
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return stats;
        }
    }
}

